import {USER_LOGIN,USER_INFO,USER_DELET} from './mutations-types'
export default{
    state:{
        //登陆状态
        loginStatus:false,
        //token
        token:null,
        //用户信息
        userInfo:{},
    },
    getters:{

    },
    mutations:{
        [USER_LOGIN] (state,user){
            state.loginStatus=true
            state.token=user.token
            state.userInfo=user

            //持久化存储==>本地存储
            localStorage.setItem('UserInfo',JSON.stringify(user))
        },
        [USER_INFO] (state){
            //获取持久化存储==>获取本地存储
            let userInfo=JSON.parse(localStorage.getItem('UserInfo'))
            if(userInfo){
                state.loginStatus=true
                state.token=userInfo.token
                state.userInfo=userInfo
            }
        },
        [USER_DELET](state){
            state.loginStatus=false
            state.token=null
            state.userInfo={}
            localStorage.removeItem('UserInfo')
            localStorage.removeItem('list')
            localStorage.removeItem('shop_orderId')
            localStorage.removeItem('shop')
            localStorage.removeItem('addr')
        }
    },
    actions:{

    }
}